#include "MyPawn.h" #include "Components/InputComponent.h"
AMyPawn::AMyPawn() { PrimaryActorTick.bCanEverTick = true;
RootComponent=CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
MyStaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MyStaticMesh")); MyStaticMesh->SetupAttachment(GetRootComponent());
MyCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("MyCamera")); MyCamera->SetupAttachment(GetRootComponent());
MyCamera->SetRelativeLocation(FVector(-300.f, 0.f, 300.f)); MyCamera->SetRelativeRotation(FRotator(-45.f, 0.f, 0.f));
AutoPossessPlayer = EAutoReceiveInput::Player0; MaxSpeed = 100.f; Velocity = FVector::ZeroVector;
}
void AMyPawn::BeginPlay() { Super::BeginPlay(); }
void AMyPawn::Tick(float DeltaTime) { Super::Tick(DeltaTime); AddActorLocalOffset(Velocity * DeltaTime, true);
}
void AMyPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) { Super::SetupPlayerInputComponent(PlayerInputComponent); PlayerInputComponent->BindAxis(TEXT("MoveForward"), this, &AMyPawn::MoveForward); PlayerInputComponent->BindAxis(TEXT("MoveRight"), this, &AMyPawn::MoveRight);
}
void AMyPawn::MoveForward(float Value) { Velocity.X = FMath::Clamp(Value, -1.f, 1.f) * MaxSpeed; }
void AMyPawn::MoveRight(float Value) { Velocity.Y = FMath::Clamp(Value, -1.f, 1.f) * MaxSpeed; }
|